const mongoose = require('mongoose')
const Bill = mongoose.model('bill')
const { formatBody } = require('../../tools')

module.exports = {
  // 任务列表
  async billList (ctx) {
    let { source } = ctx.request.body
    let list
    if (!source) {
      list = await Bill.find({})
    } else {
      list = await Bill.find({
        source
      })
    }
    return ctx.body = formatBody(1, 'ok', list)
  },
  // 任务详情
  async billDetail (ctx) {
    let { _id } = ctx.request.body
    if (!_id) {
      return ctx.body = formatBody(0, '_id不可为空')
    }
    let data = await Bill.findOne({
      _id
    }).populate({
      path: 'executor',
      select: 'avatar nickname _id'
    })
    return ctx.body = formatBody(1, 'ok', data)
  }
}